import { useUser } from '@/store/user'
import router from "@/router/index";
import { ElMessage } from 'element-plus'

export const tokenout = (before?: () => void, after?: () => void) => {


    const userStore = useUser();
    before && before()
    // 退出需要操作:
    // 1删除token,
    localStorage.removeItem("token");

    // 2清空动态路由,
    // console.log(router.getRoutes());
    console.log(userStore.menus.length);
    userStore.routes.forEach(item => {
        router.removeRoute(item.name)
    })
    console.log(router.getRoutes());

    // 3清除pinia,
    userStore.menus = [];
    userStore.username = '';


    // 4提示
    after && after()

    // 5跳转
    router.push("/login")
}